package helper.base

import org.junit.Test

internal class LHMHelperTest {
    data class CustomData(var name: String, var age: Int) {
        fun clone(): CustomData {
            return CustomData(name, age)
        }
    }

    fun A2LHM<String, CustomData>.deepClone(): A2LHM<String, CustomData> {
        val newMap = A2LHM<String, CustomData>()
        for ((key, value) in this) {
            newMap[key] = value.clone()
        }
        return newMap
    }

    @Test
    fun t1() {
        val originalMap: A2LHM<String, CustomData> = linkedMapOf(
            "key1" to CustomData("Alice", 30),
            "key2" to CustomData("Bob", 40)
        )

        val clonedMap: A2LHM<String, CustomData> = originalMap.deepClone()
        println("Original Map: $originalMap")
        println("Cloned Map: $clonedMap")

        // 修改原始对象和克隆对象，以证明它们是不同的实例
        originalMap["key1"]?.age = 35
        clonedMap["key1"]?.age = 31

        println("Modified Original Map: $originalMap")
        println("Modified Cloned Map: $clonedMap")
    }

}